package com.modbus.tcp.controller;

import java.util.List;

import com.modbus.tcp.utils.ApiReturnObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.modbus.tcp.domain.Sensortype;
import com.modbus.tcp.service.ISensortypeService;

/**
 * 传感器类型 信息操作处理
 *
 * @author d
 * @date 2024-01-11
 */
@RestController
@RequestMapping("/sensortype")
public class SensortypeController  {

    @Autowired
    private ISensortypeService sensortypeService;

    /**
     * 查询传感器类型列表
     */
    @GetMapping("/list")
    public ApiReturnObject list(Sensortype sensortype,Integer pageNum,Integer pageSize) {
        if(pageNum != null && pageSize !=null ){
            PageHelper.startPage(pageNum,pageSize);
        }
        List<Sensortype> list = sensortypeService.selectSensortypeList(sensortype);
        PageInfo pageInfo = new PageInfo<>(list);
        return new ApiReturnObject("200","查询成功",pageInfo);
    }


    /**
     * 新增保存传感器类型
     */

    @PostMapping("/add")
    public ApiReturnObject addSave(@RequestBody Sensortype sensortype) {
        sensortypeService.insertSensortype(sensortype);
        return new ApiReturnObject("200","添加成功","");
    }


    /**
     * 详情传感器类型
     */
    @GetMapping("/selectOne")
    public ApiReturnObject selectOne(Integer id){
        Sensortype result = sensortypeService.selectSensortypeById(id);
        return new ApiReturnObject("200","查询成功",result);
    }

    /**
     * 修改保存传感器类型
     */

    @PostMapping("/update")
    public ApiReturnObject editSave(@RequestBody Sensortype sensortype) {
        sensortypeService.updateSensortype(sensortype);
        return new ApiReturnObject("200","修改成功","");
    }

    /**
     * 删除传感器类型
     */

    @PostMapping("/del")
    public ApiReturnObject remove(String ids) {
        sensortypeService.deleteSensortypeByIds(ids);
        return new ApiReturnObject("200","删除成功","");
    }
}